<?php
/**
 * 
 *
 * PHP version 5.3.x
 *
 * @category 
 * @package  
 * @author   gouki <gouki.xiao@gmail.com>
 */

/**
 * SaeWebApplication.php
 *
 * @category 
 * @package  
 * @author   gouki <gouki.xiao@gmail.com>
 * @version $Id$ 
 * @created 2011-11-22 08:54
 */ 
class SaeWebApplication extends CWebApplication{

    private $_runtimePath = "saemc://";

	/**
	 * Initializes the application.
	 * This method overrides the parent implementation by preloading the 'request' component.
	 */
	protected function init(){
//        memcache_init();
        $runtimeStorage = SaeCommon::getSaeStorage('runtime');
        if(!$runtimeStorage){
            throw new CException(Yii::t("yiisae","please set runtime path in SaeStorage first, it must be privated"));
        }
		parent::init();
		// preload 'request' so that it has chance to respond to onBeginRequest event.
		$this->getRequest();
	}
	/**
	 * Registers the core application components.
	 * This method overrides the parent implementation by registering additional core components.
	 * @see setComponents
	 */
	protected function registerCoreComponents()
	{
		parent::registerCoreComponents();

		$components=array(
			'assetManager'=>array(
				'class'=>'SaeAssetManager',
			),
			'db'=>array(
				'class'=>'SaeDbConnection',
			),
			'statePersister'=>array(
				'class'=>'SaeStatePersister',
			),
        );
		$this->setComponents($components);
	}

    public function setRuntimePath($path=null){
        $this->_runtimePath = $path;
    }

    public function getRuntimePath(){
		if($this->_runtimePath!==null)
			return $this->_runtimePath;
		else
		{
			//$this->setRuntimePath("saemc://".SaeCommon::getSaeStorage('runtime'));
            //$this->setRuntimePath(SAE_TMP_PATH); //因为在写runtime的时候，都会直接采用写模式
            $this->setRuntimePath("saemc://");
			return $this->_runtimePath;
		}
    }
}
